{%- if storeConfig.pinterest_pixel_id -%}
        <!-- Pinterest Pixel Code -->
<script type="text/javascript">
    !function (e) {
        if (!window.pintrk) {
            window.pintrk = function () {
                window.pintrk.queue.push(Array.prototype.slice.call(arguments))
            };
            var
                n = window.pintrk;
            n.queue = [], n.version = "3.0";
            var
                t = document.createElement("script");
            t.async = !0, t.src = e;
            var
                r = document.getElementsByTagName("script")[0];
            r.parentNode.insertBefore(t, r)
        }
    }("https://s.pinimg.com/ct/core.js");
    pintrk('load', '{{ storeConfig.pinterest_pixel_id }}',{em: oemcart_user_email});
    pintrk('page');
    {%- if template == 'product_detail' -%}
        pintrk('track', 'pagevisit', {
        currency: "{{ base_currency.standard_code }}",
        value: '{{ product.variant.price }}',
        order_quantity: 1,
        line_items: [{
        product_id: '{{ product.spu | escape}}',
        product_quantity: 1,
        product_category: '{{ product.product_type | escape}}',
        product_price: '{{ product.variant.price }}',
        product_variant_id: '{{ product.variant.sku }}',
        product_variant: '{{product.variant.sku_value| replace: "<br />", ", "}}',
        }]
        });
    {%- elsif template == 'search_detail' -%}
        pintrk('track', 'search', {search_query: '{{ search.keywords | escape }}'});
    {%- elsif template == 'order_success' -%}
        pintrk('track', 'checkout', {
            order_quantity: "{{ order.total_num }}",
            {% if storeConfig.pinterest_enable_ga %}
            value: "{{ order.current_subtotal_price | plus:order.current_coupon_price | plus:order.current_promotion_price}}",
            {% else %}
            value: "{{ order.total_price }}",
            {% endif %}
            currency: '{{ order.currency_code }}',
            order_id: '{{ order.order_number }}',
            line_items: [
                {%- for product in order.products -%}
                {
                    product_id: '{{ product.spu | escape}}',
                    product_quantity: "{{ product.quantity }}",
                    product_category:'{{ product.product_type | escape}}',
                    {%- if storeConfig.pinterest_enable_ga -%}
                    product_price: "{{ product.discount_price }}",
                    {%- else -%}
                    product_price: "{{ product.price }}",
                    {%- endif -%}
                    product_variant_id: '{{ product.sku }}',
                    product_variant: '{{ product.sku_value | replace: "<br />", ", "}}',
                },
                {%- endfor -%}
            ]
        });
    {%- elsif template == 'collection_detail' -%}
    pintrk('track', 'ViewCategory');
    {%- endif -%}

</script>
<noscript>
    <img height="1" width="1" style="display:none;" alt=""
         src="https://ct.pinterest.com/v3/?event=init&tid={{ storeConfig.pinterest_pixel_id }}&pd[em]=<hashed_email_address>&noscript=1"/>
</noscript>
<script type="text/javascript">
    function callback_pinterest_add_to_cart(ecdata) {
        pintrk('track', 'addtocart', {
            currency: "{{ base_currency.standard_code }}",
            value: ecdata['ec_data_price']*ecdata['ec_data_quantity'],
            order_quantity: ecdata['ec_data_quantity'],
            line_items: [{
                product_id: ecdata['ec_data_spu'],
                product_quantity: ecdata['ec_data_quantity'],
                product_category: ecdata['ec_data_category'],
                product_price: ecdata['ec_data_price'],
                product_variant_id: ecdata['ec_data_sku'],
                product_variant: ecdata['ec_data_sku_name'],

            }]
        });
    }

    function callback_pinterest_generate_lead() {
        pintrk('track', 'lead');
    }

    function callback_pinterest_share_product(ec_data, platform) {
    }

    function callback_pinterest_begin_checkout() {
    }

    function callback_pinterest_login() {
    }

    function callback_pinterest_remove_from_cart(ecdata) {
    }

    function callback_pinterest_add_address_information() {
    }

    function callback_pinterest_add_shipping_information() {
    }

    function callback_pinterest_add_payment_information() {
    }

    function callback_pinterest_sign_up() {
        pintrk('track', 'signup');
    }
</script>

<!--End Pinterest Pixel Code -->
{%- endif -%}